package com.ly.controller;

import com.ly.constant.ResultCodeConstant;
import com.ly.pojo.dto.CreateGroup;
import com.ly.pojo.dto.DeleteGroup;
import com.ly.pojo.dto.FileDTO;
import com.ly.pojo.dto.NewsDTO;
import com.ly.pojo.dto.RestResult;
import com.ly.pojo.dto.UpdateGroup;
import com.ly.pojo.query.NewsQuery;
import com.ly.service.HomeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.lang.Boolean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 首页管理模块
 *
 * @author Administrator
 * @date 2025-03-07 10:51:13
 */
@Tag(name = "首页管理模块")
@RequestMapping("home")
@RestController
public class HomeController {

    @Autowired
    private HomeService homeService;

    /**
     * 新增新闻资讯
     *
     * @param newsDTO 新闻资讯信息封装
     * @return
     */
    @RequestMapping(value = "/add-news", method = RequestMethod.POST)
    @Operation(summary = "新增新闻资讯")
    @ResponseBody
    public RestResult<Boolean> addNews(@RequestBody @Validated(CreateGroup.class) NewsDTO newsDTO) {
        Boolean result = homeService.addNews(newsDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 编辑新闻资讯
     *
     * @param newsDTO 新闻资讯信息封装
     * @return
     */
    @RequestMapping(value = "/update-news", method = RequestMethod.PUT)
    @Operation(summary = "编辑新闻资讯")
    @ResponseBody
    public RestResult<Boolean> updateNews(@RequestBody @Validated(UpdateGroup.class) NewsDTO newsDTO) {
        Boolean result = homeService.updateNews(newsDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 删除新闻资讯
     *
     * @param newsQuery 新闻资讯查询条件封装
     * @return
     */
    @RequestMapping(value = "/delete-news", method = RequestMethod.DELETE)
    @Operation(summary = "删除新闻资讯")
    @ResponseBody
    public RestResult<Boolean> deleteNews(@RequestBody @Validated(DeleteGroup.class) NewsQuery newsQuery) {
        Boolean result = homeService.deleteNews(newsQuery);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 上传文件
     *
     * @param fileDTO 文件信息封装
     * @return
     */
    @RequestMapping(value = "/upload-file", method = RequestMethod.POST)
    @Operation(summary = "上传文件")
    @ResponseBody
    public RestResult<Boolean> uploadFile1(@RequestBody @Validated(CreateGroup.class) FileDTO fileDTO) {
        Boolean result = homeService.uploadFile1(fileDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }
}
